//
//  TPDetailInfoCell.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/10/25.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

const CGFloat kMarckLeft = 10.0f;
#import "TPDetailInfoCell.h"
#import "TPDetailInfoBar.h"
@interface TPDetailInfoCell()
@property (nonatomic,strong)UILabel *phoneLabel;
@property (nonatomic,strong)TPDetailInfoBar *infoBar;
@property (nonatomic,strong)TPButton *starsButton;
@end
@implementation TPDetailInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setup];
    }
    return self;
}
-(void)setup{
    
    UIImageView *line1 = [self line];
    [line1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.phoneLabel.mas_top);
    }];
    
    _infoBar = [[TPDetailInfoBar alloc]init];
    [self.contentView addSubview:_infoBar];
    [_infoBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kMarckLeft);
        make.right.mas_equalTo(-kMarckLeft);
        make.bottom.mas_equalTo(line1.mas_top);
        make.height.mas_equalTo(44.0);
    }];
    
    self.date_label.textAlignment = NSTextAlignmentRight;
    [self.date_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kMarckLeft);
        make.bottom.mas_equalTo(_infoBar.mas_top);
        make.height.mas_equalTo(38.0);
    }];
    
    self.price_label.font = fontSystemOfSize(23.0);
    self.price_label.textColor = TPAllBackgroundColor;
    [self.price_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kMarckLeft);
        make.bottom.mas_equalTo(self.date_label.mas_bottom);
        make.height.mas_equalTo(34.0);
    }];
    
    self.title_label.font = [UIFont boldSystemFontOfSize:17];
    self.title_label.numberOfLines = 0;
    [self.title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kMarckLeft);
        make.top.mas_equalTo(6.0);
        make.bottom.mas_equalTo(self.price_label.mas_top).offset(-5.0);
        make.right.mas_equalTo(self.starsButton.mas_left).offset(-5.0);
    }];
    
}
-(void)setDetailModel:(TPProductDetailModel *)detailModel{
    _detailModel = detailModel;
    self.title_label.text = detailModel.goods_name;
    self.price_label.text = [NSString stringWithFormat:@"￥%@/次",detailModel.goods_price];
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:self.price_label.text];
    [att addAttribute:NSFontAttributeName value:fontSystemOfSize(15) range:[self.price_label.text rangeOfString:@"/次"]];
    self.price_label.attributedText = att;
    self.date_label.text = [NSString stringWithFormat:@"已预约：%ld",detailModel.appoint_number];
    self.phoneLabel.text = detailModel.clinic.link_mobile;
    self.infoBar.detailModel = detailModel;
}


-(UIImageView *)line{
    UIImageView *line = [[UIImageView alloc]init];
    line.backgroundColor = TP_COLOR_240;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0.0);
        make.height.mas_equalTo(0.8);
    }];
    return line;
}
-(TPButton *)starsButton{
    if(!_starsButton){
        _starsButton = [TPButton buttonWithFrame:CGRectZero title:@"收藏" font:fontSystemOfSize(14) color:TPBlack_666666];
        _starsButton.hidden = YES;
        _starsButton.aligmentType = TPButtonAlignmentTypeCenterUp;
        [_starsButton setImage:ImageNamed(@"TP_detail_stars_normal") forState:UIControlStateNormal];
        [_starsButton setImage:ImageNamed(@"TP_detail_stars_select") forState:UIControlStateSelected];
        [self.contentView addSubview:_starsButton];
        [_starsButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kMarckLeft);
            make.top.mas_equalTo(3.0);
            make.size.mas_equalTo(CGSizeMake(0, 0));//40
        }];
    }
    return _starsButton;
}

-(UILabel *)phoneLabel{
    if(!_phoneLabel){
        
        _phoneLabel = [UILabel initWithFrame:CGRectZero font:fontSystemOfSize(15.0) color:TPBlack_999999 aligment:NSTextAlignmentRight];
        [self.contentView addSubview:_phoneLabel];
        [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kMarckLeft);
            make.bottom.mas_equalTo(0.0);
            make.height.mas_equalTo(40.0);
        }];
        
        UILabel *titleLabel = [UILabel initWithFrame:CGRectZero font:fontSystemOfSize(15.0) color:TPBlack_666666 aligment:NSTextAlignmentLeft];
        titleLabel.text = @"联系方式";
        [self.contentView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kMarckLeft);
            make.bottom.mas_equalTo(_phoneLabel.mas_bottom);
            make.height.mas_equalTo(_phoneLabel.mas_height);
        }];
    }
    
    return _phoneLabel;
}
@end
